<?php

/**
 * Albireo Kernel
 *
 * @copyright  Copyright (c) 2010 Albireo Solutions
 * @package    Kernel
 */

namespace KernelModule;
use Nette\Debug;
use Nette\Application\Presenter;

use Nette\Application\BadRequestException;


/**
 * Error presenter.
 *
 * @author     Albireo Solutions
 * @package    Kernel
 */
class ErrorPresenter extends Presenter
{

    /**
     * @param  Exception
     * @return void
     */
    public function renderDefault($exception)
    {
	if ($this->isAjax()) { // AJAX request? Just note this error in payload.
	    $this->payload->error = TRUE;
            //TODO: just the basic exception message? there should be only very basic information
            $this->payload->message = $exception->getMessage();
	    $this->terminate();

	} elseif ($exception instanceof BadRequestException) {
            $this->showMenu();
            $this->template->title = "Error 404";
	    $this->setView('404'); // load template 404.phtml

	} else {
            $this->showMenu();
            $this->template->title = "Error 500";
	    $this->setView('500'); // load template 500.phtml
	    Debug::processException($exception); // and handle error by Nette\Debug
	}
    }
}